<?php

namespace App\Logging\Processor;

use App\Logging\Service\LogService;
use App\Services\AuthService;
use Monolog\Processor\ProcessorInterface;

class SqlJsonProcessor implements ProcessorInterface
{
    /**
     * @var int 序号
     */
    protected $order = 0;

    /**
     * Invoke the processor.
     *
     * @param  array  $record
     * @return array
     */
    public function __invoke(array $record)
    {
        $record['time'] = $record['context']['time'];
        $record['timeUnit'] = 'ms';
        $record['order'] = ++$this->order;
        $record['adminId'] = AuthService::getInstance()->getAdminId();
        $record['traceId'] = LogService::getInstance()->getFinalTraceId();
        $record['datetime'] = date('Y-m-d H:i:s', strtotime($record['datetime']));
        $record['module'] = LogService::getInstance()->getModule();

        unset($record['context']);

        return $record;
    }
}
